package com.gg.controller;

import java.io.IOException;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class CommandController {
	
	private Zedis zedis;
	private ConcurrentUsers concurrentUsers;
	
	@Autowired
	public CommandController(Zedis zedis, ConcurrentUsers concurrentUsers) {
		this.zedis = zedis;
		this.concurrentUsers = concurrentUsers;
	}
	
	@RequestMapping("/command")
	public void service(String command, String userId) throws IOException {
		
		System.out.println("command arrived");
		zedis.set(command, String.valueOf(new Date().getTime()));
		
		command = command + " started";
		
		concurrentUsers.send(new Account(userId), command);
	}
}
